﻿
//var $d, $dp, $pdp = parent.$dp, $dt, $tdt, $sdt, $IE = $pdp.ie, $FF = $pdp.ff, $OPERA = $pdp.opera, $ny, $cMark = false;
(function () {
    var ScriptName = "DatePicker";
    function execute() {
        Type.registerNamespace('Kevin.Controls');
        $DatePicker = Kevin.Controls.DatePicker = function (element) {

            $DatePicker.initializeBase(this, [element]);

            this._DateFormat = Kevin.Controls.DateFormat.Date;
            this._ShowCelenderICO = true;
            this._CallbackID = null;

            this._tagetControlID = null;
            this._textBox = null;
            this._textboxID = "";
            this._format = "yyyy-MM-dd";
            this._todaysDateFormat = "yyyy-MM-dd";
            this._daysModeTitleFormat = "MMMM,yyyy";
            this._cssClass = "ajax__calendar";
            this._enabled = true;
            this._readOnly = false;
            this._animated = true;
            this._buttonID = null;
            this._layoutRequested = 0;
            this._layoutSuspended = false;
            this._button = null;
            this._popupMouseDown = false;
            this._selectedDate = null;
            this._visibleDate = null;
            this._todaysDate = null;
            this._firstDayOfWeek = Kevin.Controls.FirstDayOfWeek.Default;
            this._firstPopUp = true;

            this._container = null;
            this._popupDiv = null;
            this._header = null;
            this._prevArrow = null;
            this._nextArrow = null;
            this._title = null;
            this._body = null;
            this._footer = null;
            this._today = null;
            this._clear = null;
            this._ok = null;
            this._timesAdd = null;
            this._timesSubtract = null;
            this._secondes = null;
            this._secondesTable = null;
            this._secondesBody = null;
            this._secondInput = null;
            this._minutes = null;
            this._minutesTable = null;
            this._minutesBody = null;
            this._minuteInput = null;
            this._hours = null;
            this._hoursTable = null;
            this._hoursBody = null;
            this._hourInput = null;
            this._days = null;
            this._daysTable = null;
            this._daysTableHeader = null;
            this._daysTableHeaderRow = null;
            this._daysBody = null;
            this._months = null;
            this._monthsTable = null;
            this._monthsBody = null;
            this._years = null;
            this._yearsTable = null;
            this._yearsBody = null;
            this._popupPosition = Kevin.Controls.CalendarPosition.BottomLeft;
            this._defaultView = Kevin.Controls.CalendarDefaultView.Days;

            this._popupBehavior = null;
            this._modeChangeAnimation = null;
            this._modeChangeMoveTopOrLeftAnimation = null;
            this._modeChangeMoveBottomOrRightAnimation = null;
            this._mode = "days";
            this._operMode = ""; //用于 时分秒的加减操作
            this._selectedDateChanging = false;
            this._isOpen = false;
            this._isAnimating = false;
            this._clearTime = true; //kevin
            this._width = 170;
            this._height = 139;
            this._modes = { "days": null, "months": null, "years": null, "hours": null, "minutes": null, "secondes": null };
            this._modeOrder = { "days": 0, "months": 1, "years": 2, "hours": 3, "minutes": 4, "secondes": 5 };
            this._hourOffsetForDst = 12;  // Hour value for calls to new Date(...) to avoid DST issues
            this._blur = new Sys.Extended.UI.DeferredOperation(1, this, this.blur);

            this._button$delegates = {
                click: Function.createDelegate(this, this._button_onclick),
                keypress: Function.createDelegate(this, this._button_onkeypress),
                blur: Function.createDelegate(this, this._button_onblur)
            }
            this._element$delegates = {
                change: Function.createDelegate(this, this._element_onchange),
                keypress: Function.createDelegate(this, this._element_onkeypress),
                click: Function.createDelegate(this, this._element_onclick),
                focus: Function.createDelegate(this, this._element_onfocus),
                blur: Function.createDelegate(this, this._element_onblur)
            }
            this._popup$delegates = {
                mousedown: Function.createDelegate(this, this._popup_onmousedown),
                mouseup: Function.createDelegate(this, this._popup_onmouseup),
                drag: Function.createDelegate(this, this._popup_onevent),
                dragstart: Function.createDelegate(this, this._popup_onevent)
            }
            this._cell$delegates = {
                mouseover: Function.createDelegate(this, this._cell_onmouseover),
                mouseout: Function.createDelegate(this, this._cell_onmouseout),
                click: Function.createDelegate(this, this._cell_onclick)
            }

        }

        $DatePicker.prototype = {

            initialize: function () {

                $DatePicker.callBaseMethod(this, 'initialize');
                if (!this._tagetControlID || !$get(this._tagetControlID)) {
                    this._textBox = $common.createElementFromTemplate({
                        nodeName: "INPUT",
                        properties: {
                            type: "text",
                            id: this.get_element().id + "txtDate"
                        }
                    }, this.get_element());
                } else {
                    this._textBox = $get(this._tagetControlID);
                }
                //handler = Function.createDelegate(this, this._onClick);
                this._textBox.value = this._clientStateField.value;
                if (this._enabled == false) {
                    this._textBox.style.display = 'none';
                    var v_date = $common.createElementFromTemplate({ nodeName: 'span' }, this.get_element());
                    v_date.innerHTML = this._clientStateField.value;
                    return;
                }
                if (this._readOnly == false) {
                    //$addHandler($get(this.get_element().id), "click", handler);
                    $addHandlers(this._textBox, this._element$delegates);
                }
                else {
                    this._textBox.disabled = "disabled";
                }
                this._button = $get(this.get_element().id + "_imgDate");
                if (this._button) {
                    this._buttonID = this.get_element().id + "_imgDate";
                    this._button.style.cursor = "pointer";
                    $addHandlers(this._button, this._button$delegates);
                }
                //$addHandler(this._popupDiv, 'blur', Function.createDelegate(this, this._element_onblur));

                this._modeChangeMoveTopOrLeftAnimation = new Sys.Extended.UI.Animation.LengthAnimation(null, null, null, "style", null, 0, 0, "px");
                this._modeChangeMoveBottomOrRightAnimation = new Sys.Extended.UI.Animation.LengthAnimation(null, null, null, "style", null, 0, 0, "px");
                this._modeChangeAnimation = new Sys.Extended.UI.Animation.ParallelAnimation(null, .25, null, [this._modeChangeMoveTopOrLeftAnimation, this._modeChangeMoveBottomOrRightAnimation]);

                var value = this.get_selectedDate();
                if (value) {
                    this.set_selectedDate(value);
                }


            },
            dispose: function () {
                $DatePicker.callBaseMethod(this, 'dispose')
            },
            //方法 ---- 开始
            _onClick: function () {
                //WdatePicker({ my97DPHtm: this._My97DatePickerHtm }); //调用My97 DatePicker的方法
                //calendarEx(); // 调用梅花雨日期控件
                this.show();
            },
            show: function () {
                /// <summary>
                /// Shows the calendar
                /// </summary>

                this._ensureCalendar();

                if (!this._isOpen) {

                    var eventArgs = new Sys.CancelEventArgs();
                    this.raiseShowing(eventArgs);
                    if (eventArgs.get_cancel()) {
                        return;
                    }

                    this._isOpen = true;

                    this._popupBehavior.show();

                    if (this._firstPopUp) {
                        this._switchMonth(null, true);
                        switch (this._defaultView) {
                            case Kevin.Controls.CalendarDefaultView.Months:
                                this._switchMode("months", true);
                                break;
                            case Kevin.Controls.CalendarDefaultView.Years:
                                this._switchMode("years", true);
                                break;
                        }
                        this._firstPopUp = false;
                    }

                    this.raiseShown();
                }
            },
            hide: function () {
                /// <summary>
                /// Hides the calendar
                /// </summary>

                if (this._isOpen) {
                    var eventArgs = new Sys.CancelEventArgs();
                    this.raiseHiding(eventArgs);
                    if (eventArgs.get_cancel()) {
                        return;
                    }

                    if (this._container) {
                        this._popupBehavior.hide();
                    }
                    this._isOpen = false;
                    this.raiseHidden();

                    // make sure we clean up the flag due to issues with alert/alt-tab/etc
                    this._popupMouseDown = false;
                }
            },
            focus: function () {
                if (this._button) {
                    this._button.focus();
                } else {
                    //this.get_element().focus(); //kevin
                    this._textBox.focus();
                }
            },
            blur: function (force) {
                if (!force && Sys.Browser.agent === Sys.Browser.Opera) {
                    this._blur.post(true); //kevin
                } else {
                    if (!this._popupMouseDown) {
                        this.hide();
                    }
                    // make sure we clean up the flag due to issues with alert/alt-tab/etc
                    this._popupMouseDown = false;
                }
            },

            suspendLayout: function () {
                /// <summary>
                /// Suspends layout of the behavior while setting properties
                /// </summary>

                this._layoutSuspended++;
            },
            resumeLayout: function () {
                /// <summary>
                /// Resumes layout of the behavior and performs any pending layout requests
                /// </summary>

                this._layoutSuspended--;
                if (this._layoutSuspended <= 0) {
                    this._layoutSuspended = 0;
                    if (this._layoutRequested) {
                        this._performLayout();
                    }
                }
            },
            invalidate: function () {
                /// <summary>
                /// Performs layout of the behavior unless layout is suspended
                /// </summary>

                if (this._layoutSuspended > 0) {
                    this._layoutRequested = true;
                } else {
                    this._performLayout();
                }
            },

            _buildCalendar: function () {
                /// <summary>
                /// Builds the calendar's layout
                /// </summary>

                var elt = this.get_element();
                var id = this.get_id();

                this._container = $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: { id: id + "_container" },
                    cssClasses: [this._cssClass],
                    visible: false
                }, this._textBox.parentNode); // kevin : elt.parentNode

                this._popupDiv = $common.createElementFromTemplate({
                    nodeName: "div",
                    events: this._popup$delegates,
                    properties: {
                        id: id + "_popupDiv"
                    },
                    cssClasses: ["ajax__calendar_container"]
                }, this._container);
            },
            _buildHeader: function () {
                /// <summary>
                /// Builds the header for the calendar
                /// </summary>

                var id = this.get_id();

                this._header = $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: { id: id + "_header" },
                    cssClasses: ["ajax__calendar_header"]
                }, this._popupDiv);

                var prevArrowWrapper = $common.createElementFromTemplate({ nodeName: "div" }, this._header);
                this._prevArrow = $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: {
                        id: id + "_prevArrow",
                        mode: "prev"
                    },
                    events: this._cell$delegates,
                    cssClasses: ["ajax__calendar_prev"]
                }, prevArrowWrapper);

                var nextArrowWrapper = $common.createElementFromTemplate({ nodeName: "div" }, this._header);
                this._nextArrow = $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: {
                        id: id + "_nextArrow",
                        mode: "next"
                    },
                    events: this._cell$delegates,
                    cssClasses: ["ajax__calendar_next"]
                }, nextArrowWrapper);

                var titleWrapper = $common.createElementFromTemplate({ nodeName: "div" }, this._header);

                this._title = $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: {
                        id: id + "_title",
                        mode: "title"
                    },
                    events: this._cell$delegates,
                    cssClasses: ["ajax__calendar_title"]
                }, titleWrapper);
            },
            _buildBody: function () {
                /// <summary>
                /// Builds the body region for the calendar
                /// </summary>

                this._body = $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: { id: this.get_id() + "_body" },
                    cssClasses: ["ajax__calendar_body"]
                }, this._popupDiv);

                this._buildSecondes();
                this._buildMinutes();
                this._buildHours();
                this._buildDays();
                this._buildMonths();
                this._buildYears();
            },
            _buildFooter: function () {
                /// <summary>
                /// Builds the footer for the calendar
                /// </summary>

                this._footer = $common.createElementFromTemplate({ nodeName: "div", properties: { id: this.get_id() + "_footer"} }, this._popupDiv);

                var footerTable = $common.createElementFromTemplate({ nodeName: "table", properties: { id: this.get_id() + "_footer_table", width: '100%' }, cssClasses: ["ajax__calendar_footer_table"] }, this._footer);
                var footerTR = $common.createElementFromTemplate({ nodeName: "tr", properties: { vAlign: 'center'} }, footerTable);
                // start hours minutes secondes
                var isDateTime = this._DateFormat == Kevin.Controls.DateFormat.DateTime ? true : false;
                var footerTD_hour = $common.createElementFromTemplate({ nodeName: "td", properties: { width: '12px', rowSpan: 2, vAlign: 'center' }, cssClasses: ["ajax__calendar_footer_td"] }, footerTR);
                this._hourInput = isDateTime == true ? $common.createElementFromTemplate({
                    nodeName: "input",
                    properties: {
                        id: this.get_id() + "_hour",
                        mode: "footer_hour",
                        operMode: "hour",
                        value: new Date().getHours(),
                        rowspan: 2
                    },
                    events: this._cell$delegates,
                    cssClasses: ["ajax__calendar_input"]
                }, footerTD_hour) : null;
                isDateTime == true ? $common.createElementFromTemplate({ nodeName: "td", properties: { innerHTML: ':', width: '2px', rowSpan: 2, vAlign: 'center' }, cssClasses: ["ajax__calendar_footer_td"] }, footerTR) : "";
                var footerTD_minute = $common.createElementFromTemplate({ nodeName: "td", properties: { width: '12px', rowSpan: 2, vAlign: 'center' }, cssClasses: ["ajax__calendar_footer_td"] }, footerTR);
                this._minuteInput = isDateTime == true ? $common.createElementFromTemplate({
                    nodeName: "input",
                    properties: {
                        id: this.get_id() + "_minute",
                        mode: "footer_minute",
                        operMode: "minute",
                        value: new Date().getMinutes(),
                        rowspan: 2
                    },
                    events: this._cell$delegates,
                    cssClasses: ["ajax__calendar_input"]
                }, footerTD_minute) : null;
                isDateTime == true ? $common.createElementFromTemplate({ nodeName: "td", properties: { innerHTML: ':', width: '2px', rowSpan: 2, vAlign: 'center' }, cssClasses: ["ajax__calendar_footer_td"] }, footerTR) : "";
                var footerTD_second = isDateTime == true ? $common.createElementFromTemplate({ nodeName: "td", properties: { width: '12px', rowSpan: 2, vAlign: 'center' }, cssClasses: ["ajax__calendar_footer_td"] }, footerTR) : null;
                this._secondInput = isDateTime == true ? $common.createElementFromTemplate({
                    nodeName: "input",
                    properties: {
                        id: this.get_id() + "_second",
                        mode: "footer_second",
                        operMode: "second",
                        value: new Date().getSeconds(),
                        rowspan: 2
                    },
                    events: this._cell$delegates,
                    cssClasses: ["ajax__calendar_input"]
                }, footerTD_second) : null;
                var footerTD_add = $common.createElementFromTemplate({ nodeName: "td", properties: { width: '5px' }, cssClasses: ["ajax__calendar_footer_td"] }, footerTR);
                var footerTR2 = $common.createElementFromTemplate({ nodeName: "tr", properties: { vAlign: 'center'} }, footerTable);
                var footerTD_sub = $common.createElementFromTemplate({ nodeName: "td", properties: { width: '5px' }, cssClasses: ["ajax__calendar_footer_td"] }, footerTR2);
                this._timesAdd = isDateTime == true ? $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: {
                        id: this.get_id() + "_times_add",
                        border: 0,
                        mode: "oper",
                        oper: "add",
                        title: "加"
                    },
                    cssClasses: ["ajax__calendar_timesAdd"],
                    events: this._cell$delegates
                }, footerTD_add) : null;
                this._timesSubtract = isDateTime == true ? $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: {
                        id: this.get_id() + "_times_sub",
                        border: 0,
                        mode: "oper",
                        oper: "sub",
                        title: "减"
                    },
                    cssClasses: ["ajax__calendar_timesSub"],
                    events: this._cell$delegates
                }, footerTD_sub) : null;

                //var footerTD_today = $common.createElementFromTemplate({ nodeName: "td" }, footerTR);
                //var footer_buttons = $common.createElementFromTemplate({ nodeName: "div",cssClasses:["ajax__calendar_button_holder"] }, footerTD_today);
                var footer_td1 = $common.createElementFromTemplate({ nodeName: "td", properties: { rowSpan: 2, vAlign: 'center' }, cssClasses: ["ajax__calendar_footer_td"] }, footerTR);
                this._clear = $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: {
                        id: this.get_id() + "_clear",
                        mode: "clear",
                        innerHTML: "清空"
                    },
                    events: this._cell$delegates,
                    cssClasses: ["ajax__calendar_button"]
                }, footer_td1);
                var footer_td2 = $common.createElementFromTemplate({ nodeName: "td", properties: { rowSpan: 2, vAlign: 'center' }, cssClasses: ["ajax__calendar_footer_td"] }, footerTR);
                this._today = $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: {
                        id: this.get_id() + "_today",
                        mode: "today",
                        innerHTML: "今天",
                        date: new Date()
                    },
                    events: this._cell$delegates,
                    cssClasses: ["ajax__calendar_button"]
                }, footer_td2);
                var footer_td3 = $common.createElementFromTemplate({ nodeName: "td", properties: { rowSpan: 2, vAlign: 'center' }, cssClasses: ["ajax__calendar_footer_td"] }, footerTR);
                this._ok = $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: {
                        id: this.get_id() + "_ok",
                        mode: "ok",
                        innerHTML: "确定"
                    },
                    events: this._cell$delegates,
                    cssClasses: ["ajax__calendar_button"]
                }, footer_td3);
            },
            _buildSecondes: function () {
                ///<summary>
                ///Builds a 'Hours of the day' view for the calendar
                ///</summary>
                var id = this.get_id();
                this._secondes = $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: { id: id + "_hours" },
                    cssClasses: ["ajax__calendar_years"],
                    visible: false
                }, this._body);
                this._modes["secondes"] = this._secondes;
                this._secondesTable = $common.createElementFromTemplate({
                    nodeName: "table",
                    properties: {
                        id: id + "_secondesTable",
                        cellPadding: 0,
                        cellSpacing: 0,
                        border: 0,
                        style: { margin: "auto" }
                    }
                    // cssClass: ["ajax__calendar_hourTable"]
                }, this._secondes);

                this._secondesBody = $common.createElementFromTemplate({ nodeName: "tbody", properties: { id: id + "_minutesBody"} }, this._secondesTable);
                for (var i = 0; i < 4; i++) {
                    var secondRow = $common.createElementFromTemplate({ nodeName: "tr" }, this._secondesBody);
                    for (var j = 0; j < 3; j++) {
                        var secondCell = $common.createElementFromTemplate({
                            nodeName: "td"
                            // cssClasses: ["ajax__calendar_dayTD"]
                        }, secondRow);
                        var secondDiv = $common.createElementFromTemplate({
                            nodeName: "div",
                            properties: {
                                mode: "second",
                                operMode: "second",
                                id: id + "_second_" + i + "_" + j,
                                second: ((i * 3) + j) * 5,
                                innerHTML: ((i * 3) + j) * 5
                            },
                            events: this._cell$delegates,
                            cssClasses: ["ajax__calendar_second"]
                        }, secondCell);
                    }
                }
            },
            _buildMinutes: function () {
                ///<summary>
                ///Builds a 'Hours of the day' view for the calendar
                ///</summary>
                var id = this.get_id();
                this._minutes = $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: { id: id + "_minutes" },
                    cssClasses: ["ajax__calendar_minutes"],
                    visible: false
                }, this._body);
                this._modes["minutes"] = this._minutes;
                this._minutesTable = $common.createElementFromTemplate({
                    nodeName: "table",
                    properties: {
                        id: id + "_minutesTable",
                        cellPadding: 0,
                        cellSpacing: 0,
                        border: 0,
                        style: { margin: "auto" }
                    }
                    // cssClass: ["ajax__calendar_hourTable"]
                }, this._minutes);

                this._minutesBody = $common.createElementFromTemplate({ nodeName: "tbody", properties: { id: id + "_minutesBody"} }, this._minutesTable);
                for (var i = 0; i < 4; i++) {
                    var minutesRow = $common.createElementFromTemplate({ nodeName: "tr" }, this._minutesBody);
                    for (var j = 0; j < 3; j++) {
                        var minuteCell = $common.createElementFromTemplate({
                            nodeName: "td"
                            // cssClasses: ["ajax__calendar_dayTD"]
                        }, minutesRow);
                        var minuteDiv = $common.createElementFromTemplate({
                            nodeName: "div",
                            properties: {
                                mode: "minute",
                                operMode: "minute",
                                id: id + "_minute_" + i + "_" + j,
                                minute: ((i * 3) + j) * 5,
                                innerHTML: ((i * 3) + j) * 5
                            },
                            events: this._cell$delegates,
                            cssClasses: ["ajax__calendar_minute"]
                        }, minuteCell);
                    }
                }
            },
            _buildHours: function () {
                ///<summary>
                ///Builds a 'Hours of the day' view for the calendar
                ///</summary>
                var id = this.get_id();
                this._hours = $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: { id: id + "_hours" },
                    cssClasses: ["ajax__calendar_hours"],
                    visible: false
                }, this._body);
                this._modes["hours"] = this._hours;
                this._hoursTable = $common.createElementFromTemplate({
                    nodeName: "table",
                    properties: {
                        id: id + "_daysTable",
                        cellPadding: 0,
                        cellSpacing: 0,
                        border: 0,
                        style: { margin: "auto" }
                    }
                    // cssClass: ["ajax__calendar_hourTable"]
                }, this._hours);

                this._hoursBody = $common.createElementFromTemplate({ nodeName: "tbody", properties: { id: id + "_hoursBody"} }, this._hoursTable);
                for (var i = 0; i < 6; i++) {
                    var hoursRow = $common.createElementFromTemplate({ nodeName: "tr" }, this._hoursBody);
                    for (var j = 0; j < 4; j++) {
                        var hourCell = $common.createElementFromTemplate({
                            nodeName: "td"
                            // cssClasses: ["ajax__calendar_dayTD"]
                        }, hoursRow);
                        var hourDiv = $common.createElementFromTemplate({
                            nodeName: "div",
                            properties: {
                                mode: "hour",
                                operMode: "hour",
                                id: id + "_hour_" + i + "_" + j,
                                hour: (i * 4) + j,
                                innerHTML: (i * 4) + j
                            },
                            events: this._cell$delegates,
                            cssClasses: ["ajax__calendar_hour"]
                        }, hourCell);
                    }
                }
            },
            _buildDays: function () {
                /// <summary>
                /// Builds a "days of the month" view for the calendar
                /// </summary>

                var dtf = Sys.CultureInfo.CurrentCulture.dateTimeFormat;
                var id = this.get_id();

                this._days = $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: { id: id + "_days" },
                    cssClasses: ["ajax__calendar_days"]
                }, this._body);
                this._modes["days"] = this._days;

                this._daysTable = $common.createElementFromTemplate({
                    nodeName: "table",
                    properties: {
                        id: id + "_daysTable",
                        cellPadding: 0,
                        cellSpacing: 0,
                        border: 0,
                        style: { margin: "auto" }
                    },
                    cssClasses: ["ajax__calendar_dayTable"]
                }, this._days);

                this._daysTableHeader = $common.createElementFromTemplate({ nodeName: "thead", properties: { id: id + "_daysTableHeader"} }, this._daysTable);
                this._daysTableHeaderRow = $common.createElementFromTemplate({ nodeName: "tr", properties: { id: id + "_daysTableHeaderRow"} }, this._daysTableHeader);
                for (var i = 0; i < 7; i++) {
                    var dayCell = $common.createElementFromTemplate({ nodeName: "td" }, this._daysTableHeaderRow);
                    var dayDiv = $common.createElementFromTemplate({
                        nodeName: "div",
                        cssClasses: ["ajax__calendar_dayname"]
                    }, dayCell);
                }

                this._daysBody = $common.createElementFromTemplate({ nodeName: "tbody", properties: { id: id + "_daysBody"} }, this._daysTable);
                for (var i = 0; i < 6; i++) {
                    var daysRow = $common.createElementFromTemplate({ nodeName: "tr" }, this._daysBody);
                    for (var j = 0; j < 7; j++) {
                        var dayCell = $common.createElementFromTemplate({
                            nodeName: "td",
                            cssClasses: ["ajax__calendar_dayTD"]
                        }, daysRow);
                        var dayDiv = $common.createElementFromTemplate({
                            nodeName: "div",
                            properties: {
                                mode: "day",
                                id: id + "_day_" + i + "_" + j,
                                innerHTML: "&nbsp;"
                            },
                            events: this._cell$delegates,
                            cssClasses: ["ajax__calendar_day"]
                        }, dayCell);
                    }
                }
            },
            _buildMonths: function () {
                /// <summary>
                /// Builds a "months of the year" view for the calendar
                /// </summary>

                var dtf = Sys.CultureInfo.CurrentCulture.dateTimeFormat;
                var id = this.get_id();

                this._months = $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: { id: id + "_months" },
                    cssClasses: ["ajax__calendar_months"],
                    visible: false
                }, this._body);
                this._modes["months"] = this._months;

                this._monthsTable = $common.createElementFromTemplate({
                    nodeName: "table",
                    properties: {
                        id: id + "_monthsTable",
                        cellPadding: 0,
                        cellSpacing: 0,
                        border: 0,
                        style: { margin: "auto" }
                    }
                }, this._months);

                this._monthsBody = $common.createElementFromTemplate({ nodeName: "tbody", properties: { id: id + "_monthsBody"} }, this._monthsTable);
                for (var i = 0; i < 3; i++) {
                    var monthsRow = $common.createElementFromTemplate({ nodeName: "tr" }, this._monthsBody);
                    for (var j = 0; j < 4; j++) {
                        var monthCell = $common.createElementFromTemplate({ nodeName: "td" }, monthsRow);
                        var monthDiv = $common.createElementFromTemplate({
                            nodeName: "div",
                            properties: {
                                id: id + "_month_" + i + "_" + j,
                                mode: "month",
                                month: (i * 4) + j,
                                innerHTML: "<br />" + dtf.AbbreviatedMonthNames[(i * 4) + j]
                            },
                            events: this._cell$delegates,
                            cssClasses: ["ajax__calendar_month"]
                        }, monthCell);
                    }
                }
            },
            _buildYears: function () {
                /// <summary>
                /// Builds a "years in this decade" view for the calendar
                /// </summary>

                var id = this.get_id();

                this._years = $common.createElementFromTemplate({
                    nodeName: "div",
                    properties: { id: id + "_years" },
                    cssClasses: ["ajax__calendar_years"],
                    visible: false
                }, this._body);
                this._modes["years"] = this._years;

                this._yearsTable = $common.createElementFromTemplate({
                    nodeName: "table",
                    properties: {
                        id: id + "_yearsTable",
                        cellPadding: 0,
                        cellSpacing: 0,
                        border: 0,
                        style: { margin: "auto" }
                    }
                }, this._years);

                this._yearsBody = $common.createElementFromTemplate({ nodeName: "tbody", properties: { id: id + "_yearsBody"} }, this._yearsTable);
                for (var i = 0; i < 3; i++) {
                    var yearsRow = $common.createElementFromTemplate({ nodeName: "tr" }, this._yearsBody);
                    for (var j = 0; j < 4; j++) {
                        var yearCell = $common.createElementFromTemplate({ nodeName: "td" }, yearsRow);
                        var yearDiv = $common.createElementFromTemplate({
                            nodeName: "div",
                            properties: {
                                id: id + "_year_" + i + "_" + j,
                                mode: "year",
                                year: ((i * 4) + j) - 1
                            },
                            events: this._cell$delegates,
                            cssClasses: ["ajax__calendar_year"]
                        }, yearCell);
                    }
                }
            },

            _performLayout: function () {
                /// <summmary>
                /// Updates the various views of the calendar to match the current selected and visible dates
                /// </summary>

                var elt = this.get_element();
                if (!elt) return;
                if (!this.get_isInitialized()) return;
                if (!this._isOpen) return;

                var dtf = Sys.CultureInfo.CurrentCulture.dateTimeFormat;
                var selectedDate = this.get_selectedDate();
                var visibleDate = this._getEffectiveVisibleDate();
                var todaysDate = this.get_todaysDate();
                if (this._DateFormat == Kevin.Controls.DateFormat.DateTime) {
                    //this._hourInput.value = selectedDate.getHours();
                    //this._minuteInput.value = selectedDate.getMinutes();
                    //this._secondInput.value = selectedDate.getSeconds();
                }
                switch (this._mode) {
                    case "days":

                        var firstDayOfWeek = this._getFirstDayOfWeek();
                        var daysToBacktrack = visibleDate.getDay() - firstDayOfWeek;
                        if (daysToBacktrack <= 0)
                            daysToBacktrack += 7;

                        var startDate = new Date(visibleDate.getFullYear(), visibleDate.getMonth(), visibleDate.getDate() - daysToBacktrack, this._hourOffsetForDst);
                        var currentDate = startDate;

                        for (var i = 0; i < 7; i++) {
                            var dayCell = this._daysTableHeaderRow.cells[i].firstChild;
                            if (dayCell.firstChild) {
                                dayCell.removeChild(dayCell.firstChild);
                            }
                            dayCell.appendChild(document.createTextNode(dtf.ShortestDayNames[(i + firstDayOfWeek) % 7]));
                        }
                        for (var week = 0; week < 6; week++) {
                            var weekRow = this._daysBody.rows[week];
                            for (var dayOfWeek = 0; dayOfWeek < 7; dayOfWeek++) {
                                var dayCell = weekRow.cells[dayOfWeek].firstChild;
                                if (dayCell.firstChild) {
                                    dayCell.removeChild(dayCell.firstChild);
                                }
                                dayCell.appendChild(document.createTextNode(currentDate.getDate()));
                                dayCell.title = currentDate.localeFormat("D");
                                dayCell.date = currentDate;
                                $common.removeCssClasses(dayCell.parentNode, ["ajax__calendar_other", "ajax__calendar_active"]);
                                Sys.UI.DomElement.addCssClass(dayCell.parentNode, this._getCssClass(dayCell.date, 'd'));
                                currentDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate() + 1, this._hourOffsetForDst);
                            }
                        }

                        this._prevArrow.date = new Date(visibleDate.getFullYear(), visibleDate.getMonth() - 1, 1, this._hourOffsetForDst);
                        this._nextArrow.date = new Date(visibleDate.getFullYear(), visibleDate.getMonth() + 1, 1, this._hourOffsetForDst);
                        if (this._title.firstChild) {
                            this._title.removeChild(this._title.firstChild);
                        }

                        this._title.appendChild(document.createTextNode(visibleDate.localeFormat(this.get_daysModeTitleFormat())));

                        this._title.date = visibleDate;

                        break;
                    case "months":

                        for (var i = 0; i < this._monthsBody.rows.length; i++) {
                            var row = this._monthsBody.rows[i];
                            for (var j = 0; j < row.cells.length; j++) {
                                var cell = row.cells[j].firstChild;
                                cell.date = new Date(visibleDate.getFullYear(), cell.month, 1, this._hourOffsetForDst);
                                cell.title = cell.date.localeFormat("Y");
                                $common.removeCssClasses(cell.parentNode, ["ajax__calendar_other", "ajax__calendar_active"]);
                                Sys.UI.DomElement.addCssClass(cell.parentNode, this._getCssClass(cell.date, 'M'));
                            }
                        }

                        if (this._title.firstChild) {
                            this._title.removeChild(this._title.firstChild);
                        }

                        this._title.appendChild(document.createTextNode(visibleDate.localeFormat("yyyy")));
                        this._title.date = visibleDate;
                        this._prevArrow.date = new Date(visibleDate.getFullYear() - 1, 0, 1, this._hourOffsetForDst);
                        this._nextArrow.date = new Date(visibleDate.getFullYear() + 1, 0, 1, this._hourOffsetForDst);

                        break;
                    case "years":

                        var minYear = (Math.floor(visibleDate.getFullYear() / 10) * 10);
                        for (var i = 0; i < this._yearsBody.rows.length; i++) {
                            var row = this._yearsBody.rows[i];
                            for (var j = 0; j < row.cells.length; j++) {
                                var cell = row.cells[j].firstChild;
                                cell.date = new Date(minYear + cell.year, 0, 1, this._hourOffsetForDst);
                                if (cell.firstChild) {
                                    cell.removeChild(cell.lastChild);
                                } else {
                                    cell.appendChild(document.createElement("br"));
                                }
                                cell.appendChild(document.createTextNode(minYear + cell.year));
                                $common.removeCssClasses(cell.parentNode, ["ajax__calendar_other", "ajax__calendar_active"]);
                                Sys.UI.DomElement.addCssClass(cell.parentNode, this._getCssClass(cell.date, 'y'));
                            }
                        }

                        if (this._title.firstChild) {
                            this._title.removeChild(this._title.firstChild);
                        }

                        this._title.appendChild(document.createTextNode(minYear.toString() + "-" + (minYear + 9).toString()));
                        this._title.date = visibleDate;
                        this._prevArrow.date = new Date(minYear - 10, 0, 1, this._hourOffsetForDst);
                        this._nextArrow.date = new Date(minYear + 10, 0, 1, this._hourOffsetForDst);
                        break;

                }
                //if (this._today.firstChild) {
                //    this._today.removeChild(this._today.firstChild);
                //}
                //this._today.appendChild(document.createTextNode(String.format(Sys.Extended.UI.Resources.Calendar_Today, todaysDate.localeFormat(this.get_todaysDateFormat()))));

                //this._today.date = todaysDate;
            },

            _ensureCalendar: function () {

                if (!this._container) {

                    var elt = this._textBox;

                    this._buildCalendar();
                    this._buildHeader();
                    this._buildBody();
                    this._buildFooter();

                    this._popupBehavior = new $create(Sys.Extended.UI.PopupBehavior, { id: this.get_id() + '_popBehavior', 'parentElement': elt, "positioningMode": Sys.Extended.UI.PositioningMode.BottomLeft }, null, null, this._container);
                    if (this._popupPosition == Kevin.Controls.CalendarPosition.TopLeft) {
                        this._popupBehavior.set_positioningMode(Sys.Extended.UI.PositioningMode.TopLeft);
                    } else if (this._popupPosition == Kevin.Controls.CalendarPosition.TopRight) {
                        this._popupBehavior.set_positioningMode(Sys.Extended.UI.PositioningMode.TopRight);
                    } else if (this._popupPosition == Kevin.Controls.CalendarPosition.BottomRight) {
                        this._popupBehavior.set_positioningMode(Sys.Extended.UI.PositioningMode.BottomRight);
                    } else if (this._popupPosition == Kevin.Controls.CalendarPosition.Right) {
                        this._popupBehavior.set_positioningMode(Sys.Extended.UI.PositioningMode.Right);
                    } else if (this._popupPosition == Kevin.Controls.CalendarPosition.Left) {
                        this._popupBehavior.set_positioningMode(Sys.Extended.UI.PositioningMode.Left);
                    } else {
                        //this._popupBehavior.set_positioningMode(Sys.Extended.UI.PositioningMode.BottomLeft);
                    }
                }
            },

            _fireChanged: function () {
                /// <summary>
                /// Attempts to fire the change event on the attached textbox
                /// </summary>

                var elt = this.get_element();
                if (document.createEventObject) {
                    //elt.fireEvent("onchange");
                } else if (document.createEvent) {
                    //var e = document.createEvent("HTMLEvents");
                    //e.initEvent("change", true, true);
                    //elt.dispatchEvent(e);
                }
            },
            _switchMonth: function (date, dontAnimate) {
                /// <summary>
                /// Switches the visible month in the days view
                /// </summary>
                /// <param name="date" type="Date">The visible date to switch to</param>
                /// <param name="dontAnimate" type="Boolean">Prevents animation from occuring if the control is animated</param>

                // Check _isAnimating to make sure we don't animate horizontally and vertically at the same time
                if (this._isAnimating) {
                    return;
                }

                var visibleDate = this._getEffectiveVisibleDate();
                //if ((date && date.getFullYear() == visibleDate.getFullYear() && date.getMonth() == visibleDate.getMonth())) {
                dontAnimate = true;
                //}

                if (this._animated && !dontAnimate) {
                    this._isAnimating = true;

                    var newElement = this._modes[this._mode];
                    var oldElement = newElement.cloneNode(true);
                    this._body.appendChild(oldElement);
                    if (visibleDate > date) {

                        // animating down
                        // the newIndex element is the top
                        // the oldIndex element is the bottom (visible)

                        // move in, fade in
                        $common.setLocation(newElement, { x: -162, y: 0 });
                        $common.setVisible(newElement, true);
                        this._modeChangeMoveTopOrLeftAnimation.set_propertyKey("left");
                        this._modeChangeMoveTopOrLeftAnimation.set_target(newElement);
                        this._modeChangeMoveTopOrLeftAnimation.set_startValue(-this._width);
                        this._modeChangeMoveTopOrLeftAnimation.set_endValue(0);

                        // move out, fade out
                        $common.setLocation(oldElement, { x: 0, y: 0 });
                        $common.setVisible(oldElement, true);
                        this._modeChangeMoveBottomOrRightAnimation.set_propertyKey("left");
                        this._modeChangeMoveBottomOrRightAnimation.set_target(oldElement);
                        this._modeChangeMoveBottomOrRightAnimation.set_startValue(0);
                        this._modeChangeMoveBottomOrRightAnimation.set_endValue(this._width);

                    } else {
                        // animating up
                        // the oldIndex element is the top (visible)
                        // the newIndex element is the bottom

                        // move out, fade out
                        $common.setLocation(oldElement, { x: 0, y: 0 });
                        $common.setVisible(oldElement, true);
                        this._modeChangeMoveTopOrLeftAnimation.set_propertyKey("left");
                        this._modeChangeMoveTopOrLeftAnimation.set_target(oldElement);
                        this._modeChangeMoveTopOrLeftAnimation.set_endValue(-this._width);
                        this._modeChangeMoveTopOrLeftAnimation.set_startValue(0);

                        // move in, fade in
                        $common.setLocation(newElement, { x: 162, y: 0 });
                        $common.setVisible(newElement, true);
                        this._modeChangeMoveBottomOrRightAnimation.set_propertyKey("left");
                        this._modeChangeMoveBottomOrRightAnimation.set_target(newElement);
                        this._modeChangeMoveBottomOrRightAnimation.set_endValue(0);
                        this._modeChangeMoveBottomOrRightAnimation.set_startValue(this._width);
                    }
                    this._visibleDate = date;
                    this.invalidate();

                    var endHandler = Function.createDelegate(this, function () {
                        this._body.removeChild(oldElement);
                        oldElement = null;
                        this._isAnimating = false;
                        this._modeChangeAnimation.remove_ended(endHandler);
                    });
                    this._modeChangeAnimation.add_ended(endHandler);
                    this._modeChangeAnimation.play();
                } else {
                    this._visibleDate = date;
                    this.invalidate();
                }
            },
            _switchMode: function (mode, dontAnimate) {
                /// <summary>
                /// Switches the visible view from "days" to "months" to "years"
                /// </summary>
                /// <param name="mode" type="String">The view mode to switch to</param>
                /// <param name="dontAnimate" type="Boolean">Prevents animation from occuring if the control is animated</param>

                // Check _isAnimating to make sure we don't animate horizontally and vertically at the same time
                if (this._isAnimating || (this._mode == mode)) {
                    return;
                }

                var moveDown = this._modeOrder[this._mode] < this._modeOrder[mode];
                var oldElement = this._modes[this._mode];
                var newElement = this._modes[mode];
                this._mode = mode;

                if (this._animated && !dontAnimate) {
                    this._isAnimating = true;

                    this.invalidate();

                    if (moveDown) {
                        // animating down
                        // the newIndex element is the top
                        // the oldIndex element is the bottom (visible)

                        // move in, fade in
                        $common.setLocation(newElement, { x: 0, y: -this._height });
                        $common.setVisible(newElement, true);
                        this._modeChangeMoveTopOrLeftAnimation.set_propertyKey("top");
                        this._modeChangeMoveTopOrLeftAnimation.set_target(newElement);
                        this._modeChangeMoveTopOrLeftAnimation.set_startValue(-this._height);
                        this._modeChangeMoveTopOrLeftAnimation.set_endValue(0);

                        // move out, fade out
                        $common.setLocation(oldElement, { x: 0, y: 0 });
                        $common.setVisible(oldElement, true);

                        this._modeChangeMoveBottomOrRightAnimation.set_propertyKey("top");
                        this._modeChangeMoveBottomOrRightAnimation.set_target(oldElement);
                        this._modeChangeMoveBottomOrRightAnimation.set_startValue(0);
                        this._modeChangeMoveBottomOrRightAnimation.set_endValue(this._height);

                    } else {
                        // animating up
                        // the oldIndex element is the top (visible)
                        // the newIndex element is the bottom

                        // move out, fade out
                        $common.setLocation(oldElement, { x: 0, y: 0 });
                        $common.setVisible(oldElement, true);
                        this._modeChangeMoveTopOrLeftAnimation.set_propertyKey("top");
                        this._modeChangeMoveTopOrLeftAnimation.set_target(oldElement);
                        this._modeChangeMoveTopOrLeftAnimation.set_endValue(-this._height);
                        this._modeChangeMoveTopOrLeftAnimation.set_startValue(0);

                        // move in, fade in
                        $common.setLocation(newElement, { x: 0, y: 139 });
                        $common.setVisible(newElement, true);
                        this._modeChangeMoveBottomOrRightAnimation.set_propertyKey("top");
                        this._modeChangeMoveBottomOrRightAnimation.set_target(newElement);
                        this._modeChangeMoveBottomOrRightAnimation.set_endValue(0);
                        this._modeChangeMoveBottomOrRightAnimation.set_startValue(this._height);
                    }
                    var endHandler = Function.createDelegate(this, function () {
                        this._isAnimating = false;
                        this._modeChangeAnimation.remove_ended(endHandler);
                    });
                    this._modeChangeAnimation.add_ended(endHandler);
                    this._modeChangeAnimation.play();
                } else {
                    this._mode = mode;
                    $common.setVisible(oldElement, false);
                    this.invalidate();
                    $common.setVisible(newElement, true);
                    $common.setLocation(newElement, { x: 0, y: 0 });
                }
            },
            _AddSub: function (oper) {
                if (oper == "add") {
                    switch (this._operMode) {
                        case "hour":
                            var hour = this._hourInput.value.valueOf();
                            if (hour < 23) hour++;
                            this._hourInput.value = hour;
                            break;
                        case "minute":
                            var minute = this._minuteInput.value.valueOf();
                            if (minute < 59) minute++;
                            this._minuteInput.value = minute;
                            break;
                        case "second":
                            var second = this._secondInput.value.valueOf();
                            if (second < 59) second++;
                            this._secondInput.value = second;
                            break;
                    }
                    $common.setVisible(this._days, true);
                }
                if (oper == "sub") {
                    switch (this._operMode) {
                        case "hour":
                            var hour = this._hourInput.value.valueOf();
                            if (hour > 0) hour--;
                            this._hourInput.value = hour;
                            break;
                        case "minute":
                            var minute = this._minuteInput.value.valueOf();
                            if (minute > 0) minute--;
                            this._minuteInput.value = minute;
                            break;
                        case "second":
                            var second = this._secondInput.value.valueOf();
                            if (second > 0) second--;
                            this._secondInput.value = second;
                            break;
                    }
                }
                this._hourInput.value = this._hourInput.value.length < 2 ? "0" + this._hourInput.value : this._hourInput.value;
                this._minuteInput.value = this._minuteInput.value.length < 2 ? "0" + this._minuteInput.value : this._minuteInput.value;
                this._secondInput.value = this._secondInput.value.length < 2 ? "0" + this._secondInput.value : this._secondInput.value;
            },
            _isSelected: function (date, part) {
                /// <summary>
                /// Gets whether the supplied date is the currently selected date
                /// </summary>
                /// <param name="date" type="Date">The date to match</param>
                /// <param name="part" type="String">The most significant part of the date to test</param>
                /// <returns type="Boolean" />
                var value = this.get_selectedDate();
                if (!value) return false;
                switch (part) {
                    case 'd':
                        if (date.getDate() != value.getDate()) return false;
                        // goto case 'M';
                    case 'M':
                        if (date.getMonth() != value.getMonth()) return false;
                        // goto case 'y';
                    case 'y':
                        if (date.getFullYear() != value.getFullYear()) return false;
                        break;
                }
                return true;
            },
            _isOther: function (date, part) {
                /// <summary>
                /// Gets whether the supplied date is in a different view from the current visible month
                /// </summary>
                /// <param name="date" type="Date">The date to match</param>
                /// <param name="part" type="String">The most significant part of the date to test</param>
                /// <returns type="Boolean" />

                var value = this._getEffectiveVisibleDate();
                switch (part) {
                    case 'd':
                        return (date.getFullYear() != value.getFullYear() || date.getMonth() != value.getMonth());
                    case 'M':
                        return false;
                    case 'y':
                        var minYear = (Math.floor(value.getFullYear() / 10) * 10);
                        return date.getFullYear() < minYear || (minYear + 10) <= date.getFullYear();
                }
                return false;
            },
            _getCssClass: function (date, part) {
                /// <summary>
                /// Gets the cssClass to apply to a cell based on a supplied date
                /// </summary>
                /// <param name="date" type="Date">The date to match</param>
                /// <param name="part" type="String">The most significant part of the date to test</param>
                /// <returns type="String" />

                if (this._isSelected(date, part)) {
                    return "ajax__calendar_active";
                } else if (this._isOther(date, part)) {
                    return "ajax__calendar_other";
                } else {
                    return "";
                }
            },
            _getEffectiveVisibleDate: function () {
                var value = this.get_visibleDate();
                if (value == null)
                    value = this.get_selectedDate();
                if (value == null)
                    value = this.get_todaysDate();
                return new Date(value.getFullYear(), value.getMonth(), 1, this._hourOffsetForDst);
                return new Date();
            },
            _getFirstDayOfWeek: function () {
                /// <summary>
                /// Gets the first day of the week
                /// </summary>

                if (this.get_firstDayOfWeek() != Kevin.Controls.FirstDayOfWeek.Default) {
                    return this.get_firstDayOfWeek();
                }
                return Sys.CultureInfo.CurrentCulture.dateTimeFormat.FirstDayOfWeek;
            },
            _parseTextValue: function (text) {
                /// <summary>
                /// Converts a text value from the textbox into a date
                /// </summary>
                /// <param name="text" type="String" mayBeNull="true">The text value to parse</param>
                /// <returns type="Date" />

                var value = null;
                if (text) {
                    value = Date.parseLocale(text, this.get_format());
                }
                if (isNaN(value)) {
                    value = null;
                }
                return value;
            },

            _element_onfocus: function (e) {
                /// <summary> 
                /// Handles the focus event of the element
                /// </summary>
                /// <param name="e" type="Sys.UI.DomEvent">The arguments for the event</param>
                if (!this._enabled) return;
                if (!this._button) {
                    this.show();
                    // make sure we clean up the flag due to issues with alert/alt-tab/etc
                    this._popupMouseDown = false;
                }
            },
            _element_onblur: function (e) {
                /// <summary> 
                /// Handles the blur event of the element
                /// </summary>
                /// <param name="e" type="Sys.UI.DomEvent">The arguments for the event</param>
                if (!this._enabled) return;
                //var reg = "/^((((((0[48])|([13579][26])|([2468][048]))00)|([0-9][0-9]((0[48])|([13579][26])|([2468][048]))))-02-29)|(((000[1-9])|(00[1-9][0-9])|(0[1-9][0-9][0-9])|([1-9][0-9][0-9][0-9]))-((((0[13578])|(1[02]))-31)|(((0[1,3-9])|(1[0-2]))-(29|30))|(((0[1-9])|(1[0-2]))-((0[1-9])|(1[0-9])|(2[0-8]))))))$/";
                //var inputDate = new Date(Date.parse(this._textBox.value.replace(/[-]/g, '/'))).getDateOnly().localeFormat(this._format);
                //if (inputDate.toString().match(reg) == null) {
                //    alert('日期错误!');
                //    return;
                //}
                if (!this._checkDate(this._textBox.value)) {
                    alert("日期错误");
                    this._textBox.focus();
                    return;
                }
                this._clientStateField.value = this._textBox.value;
                if (!this._button) {
                    this.blur();
                }
            },
            _element_onchange: function (e) {
                /// <summary> 
                /// Handles the change event of the element
                /// </summary>
                /// <param name="e" type="Sys.UI.DomEvent">The arguments for the event</param>
                if (!this._selectedDateChanging) {
                    var value = this._parseTextValue(this._textBox.value);
                    if (value) value = value.getDateOnly();
                    this._selectedDate = value;
                    if (this._isOpen) {
                        this._switchMonth(this._selectedDate, this._selectedDate == null);
                    }
                }
            },
            _element_onkeypress: function (e) {
                /// <summary>
                /// Handles the keypress event of the element
                /// </summary>
                /// <param name="e" type="Sys.UI.DomEvent">The arguments for the event</param>
                if (!this._enabled) return;
                if (!this._button && e.charCode == Sys.UI.Key.esc) {
                    e.stopPropagation();
                    e.preventDefault();
                    this.hide();
                }
            },
            _element_onclick: function (e) {
                /// <summary>
                /// Handles the click event of the element
                /// </summary>
                /// <param name="e" type="Sys.UI.DomEvent">The arguments for the event</param>
                if (!this._enabled) return;
                if (!this._button) {
                    this.show();
                    // make sure we clean up the flag due to issues with alert/alt-tab/etc
                    this._popupMouseDown = false;
                }
            },

            _popup_onevent: function (e) {
                /// <summary> 
                /// Handles the drag-start event of the popup calendar
                /// </summary>
                /// <param name="e" type="Sys.UI.DomEvent">The arguments for the event</param>
                e.stopPropagation();
                e.preventDefault();
            },
            _popup_onmousedown: function (e) {
                /// <summary> 
                /// Handles the mousedown event of the popup
                /// </summary>
                /// <param name="e" type="Sys.UI.DomEvent">The arguments for the event</param>

                // signal that the popup has received a mousedown event, this handles
                // onblur issues on browsers like FF, OP, and SF
                this._popupMouseDown = true;
            },
            _popup_onmouseup: function (e) {
                /// <summary> 
                /// Handles the mouseup event of the popup
                /// </summary>
                /// <param name="e" type="Sys.UI.DomEvent">The arguments for the event</param>

                // signal that the popup has received a mouseup event, this handles
                // onblur issues on browsers like FF, OP, and SF
                if (Sys.Browser.agent === Sys.Browser.Opera && this._blur.get_isPending()) {
                    this._blur.cancel();
                }
                this._popupMouseDown = false;
                this.focus();
            },

            _cell_onmouseover: function (e) {
                /// <summary> 
                /// Handles the mouseover event of a cell
                /// </summary>
                /// <param name="e" type="Sys.UI.DomEvent">The arguments for the event</param>

                e.stopPropagation();

                if (Sys.Browser.agent === Sys.Browser.Safari) {
                    // Safari doesn't reliably call _cell_onmouseout, so clear other cells here to keep the UI correct
                    for (var i = 0; i < this._daysBody.rows.length; i++) {
                        var row = this._daysBody.rows[i];
                        for (var j = 0; j < row.cells.length; j++) {
                            Sys.UI.DomElement.removeCssClass(row.cells[j].firstChild.parentNode, "ajax__calendar_hover");
                        }
                    }
                }

                var target = e.target;

                Sys.UI.DomElement.addCssClass(target.parentNode, "ajax__calendar_hover");
            },
            _cell_onmouseout: function (e) {
                /// <summary> 
                /// Handles the mouseout event of a cell
                /// </summary>
                /// <param name="e" type="Sys.UI.DomEvent">The arguments for the event</param>

                e.stopPropagation();

                var target = e.target;

                Sys.UI.DomElement.removeCssClass(target.parentNode, "ajax__calendar_hover");
            },
            _cell_onclick: function (e) {
                /// <summary> 
                /// Handles the click event of a cell
                /// </summary>
                /// <param name="e" type="Sys.UI.DomEvent">The arguments for the event</param>

                e.stopPropagation();
                e.preventDefault();

                if (!this._enabled) return;

                var target = e.target;
                var visibleDate = this._getEffectiveVisibleDate();
                Sys.UI.DomElement.removeCssClass(target.parentNode, "ajax__calendar_hover");
                switch (target.mode) {
                    case "prev":
                    case "next":
                        this._switchMonth(target.date);
                        break;
                    case "title":
                        switch (this._mode) {
                            case "hours":
                            case "minutes":
                            case "secondes":
                            case "days": this._switchMode("months"); break;
                            case "months": this._switchMode("years"); break;
                        }
                        break;
                    case "month":
                        if (target.month == visibleDate.getMonth()) {
                            this._switchMode("days");
                        } else {
                            this._visibleDate = target.date;
                            this._switchMode("days");
                        }
                        break;
                    case "year":
                        if (target.date.getFullYear() == visibleDate.getFullYear()) {
                            this._switchMode("months");
                        } else {
                            this._visibleDate = target.date;
                            this._switchMode("months");
                        }
                        break;
                    case "day":
                        if (this._DateFormat == Kevin.Controls.DateFormat.DateTime) {
                            //this._clientStateField.value = target.date.localeFormat(this._format);
                            this._selectedDate = target.date;
                            break; //如果日期格式为yyyy-MM-dd HH:mm-ss 则此时不能隐藏控件，需待客户选择时间后点击"确定"方可赋值并隐藏控件
                        }
                        this.set_selectedDate(target.date);
                        this._switchMonth(target.date);
                        this._blur.post(true); //kevin
                        this.raiseDateSelectionChanged();
                        break;
                    case "today":
                        this.set_selectedDate(target.date);
                        this._switchMonth(target.date);
                        this._blur.post(true); //kevin
                        this.raiseDateSelectionChanged();
                        break;
                    case "footer_hour":
                        this._switchMode("hours");
                        this._operMode = target.operMode;
                        break;
                    case "hour":
                        this._hourInput.value = target.hour;
                        this._operMode = target.operMode;
                        this._switchMode("days");
                        break;
                    case "footer_minute":
                        this._switchMode("minutes");
                        this._operMode = target.operMode;
                        //this.raiseDateSelectionChanged();
                        break;
                    case "minute":
                        this._minuteInput.value = target.minute;
                        this._operMode = target.operMode;
                        this._switchMode("days");
                        break;
                    case "footer_second":
                        this._switchMode("secondes");
                        this._operMode = target.operMode;
                        break;
                    case "second":
                        this._secondInput.value = target.second;
                        this._operMode = target.operMode;
                        this._switchMode("days");
                        break;
                    case "oper":
                        this._AddSub(target.oper);
                        this._switchMode("days");
                        break;
                    case "clear":
                        this._textBox.value = "";
                        this._clientStateField.value = "";
                        if (this._selectedDate) {
                            this._selectedDate = null;
                        }
                        this._blur.post(true);
                        this.raiseDateSelectionChanged();
                        break;
                    case "ok":
                        //var selectedDate = null;
                        if (!this._selectedDate && this._clientStateField.value != "") {
                            //selectedDate = new Date(Date.parse(this._clientStateField.value.replace(/[-]/g, '/')));
                            this._selectedDate = new Date(Date.parse(this._clientStateField.value.replace(/[-]/g, '/'))).getDateOnly();
                        }

                        if (!this._selectedDate) this._selectedDate = new Date().getDateOnly();
                        if (this.DateFormat == Kevin.Controls.DateTime) {
                            var formatDatePart = this._format.split(' ')[0];
                            this._clientStateField.value = this._selectedDate.getDateOnly().localeFormat(formatDatePart) + " " + this._hourInput.value + ":" + this._minuteInput.value + ":" + this._secondInput.value;
                        }

                        this._textBox.value = this._clientStateField.value;
                        this.set_selectedDate(this._selectedDate);
                        this._switchMonth(this._selectedDate);
                        this._blur.post(true); //kevin
                        this.raiseDateSelectionChanged();
                        break;
                }
                //this._textBox.setFocus();
            },

            _button_onclick: function (e) {
                /// <summary> 
                /// Handles the click event of the asociated button
                /// </summary>
                /// <param name="e" type="Sys.UI.DomEvent">The arguments for the event</param>

                e.preventDefault();
                e.stopPropagation();

                if (!this._enabled) return;

                if (!this._isOpen) {
                    this.show();
                } else {
                    this.hide();
                }
                this.focus();
                // make sure we clean up the flag due to issues with alert/alt-tab/etc
                this._popupMouseDown = false;
                // set to the date currently in the text box
                if (this._visibleDate != this._selectedDate) {
                    this._visibleDate = this._selectedDate
                    this.invalidate();
                }
            },
            _button_onblur: function (e) {
                /// <summary> 
                /// Handles the blur event of the button
                /// </summary>
                /// <param name="e" type="Sys.UI.DomEvent">The arguments for the event</param>
                if (!this._enabled) return;
                if (!this._popupMouseDown) {
                    this.hide();
                }
                // make sure we clean up the flag due to issues with alert/alt-tab/etc
                this._popupMouseDown = false;
            },
            _button_onkeypress: function (e) {
                /// <summary>
                /// Handles the keypress event of the element
                /// </summary>
                /// <param name="e" type="Sys.UI.DomEvent">The arguments for the event</param>
                if (!this._enabled) return;
                if (e.charCode == Sys.UI.Key.esc) {
                    e.stopPropagation();
                    e.preventDefault();
                    this.hide();
                }
                // make sure we clean up the flag due to issues with alert/alt-tab/etc
                this._popupMouseDown = false;
            },
            _checkDate: function (strDate) {
                if (strDate === "") {
                    return true;
                }
                var intDay, intMonth, intYear, intHour, intMinute, intSecond, datePart, timePart;
                datePart = strDate.split(' ')[0];
                timePart = strDate.split(' ')[1];
                if (datePart.indexOf('-') > 0) {
                    //日期部分校验
                    var intYear = datePart.substring(0, datePart.indexOf('-'));
                    var intMonth = datePart.substring(datePart.indexOf('-') + 1, datePart.lastIndexOf('-'));
                    if (intMonth.substring(0, 1) == '0' && intMonth.length > 1)
                        intMonth = intMonth.substring(1, intMonth.length);
                    var intDay = datePart.substring(datePart.lastIndexOf('-') + 1, datePart.length);
                    if (intDay.substring(0, 1) == '0' && intDay.length > 1)
                        intDay = intDay.substring(1, intDay.length);
                    if (this._checkNumber(intDay) == false || this._checkNumber(intMonth) == false || this._checkNumber(intYear) == false)
                        return false;
                    if (intMonth > 12 || intMonth < 1)
                        return false;
                    if (intDay > 31 || intDay < 1)
                        return false;
                    if (intYear < 1900 || intYear > 2900)
                        return false;
                    if (intMonth == 2) {
                        if (intYear % 4 == 0 && intDay > 29)
                            return false;
                        if (intYear % 400 == 0 && intDay > 29)
                            return false;
                        if (intYear % 4 != 0 && intDay > 28)
                            return false;
                    }
                    for (var i = 1; i <= 12; i = i + 2) {
                        if (intMonth == i) {
                            if (intDay > 31)
                                return false;
                        }
                        if (i == 7)
                            --i;
                    }
                    for (i = 4; i <= 11; i = i + 2) {
                        if (intMonth == i) {
                            if (intDay > 30)
                                return false;
                        }
                        if (i == 6)
                            i++;
                    }
                    //时间部分校验
                    if (this._DateFormat == Kevin.Controls.DateFormat.DateTime && timePart.length > 0) {
                        intHour = timePart.substring(0, timePart.indexOf(':'));
                        if (intHour.substring(0, 1) == '0') intHour = intHour.substring(1, 1);
                        intMinute = timePart.substring(timePart.indexOf(':') + 1, timePart.lastIndexOf(':'));
                        if (intMinute.substring(0, 1) == '0') intMinute = intMinute.substring(1, 1);
                        intSecond = timePart.substring(timePart.lastIndexOf(':') + 1, timePart.length);
                        if (intSecond.substring(0, 1) == '0') intSecond = intSecond.substring(1, 1);

                        if (intHour < 0 || intHour > 23) return false;
                        if (intMinute < 0 || intMinute > 59) return false;
                        if (intSecond < 0 || intSecond > 59) return false;
                    }

                    //以上日期时间校验都通过则返回true
                    return true;
                }
                else
                    return false;
            },
            _checkNumber: function (strNumber) {
                for (var i = 0; i < strNumber.length; ++i) {
                    var c = strNumber.charCodeAt(i);
                    if (c < 48 || c > 57)
                        return false;
                }
                return true;
            },
            //方法 ---- 结束
            //属性 ---- 开始tagetControlID
            get_tagetControlID: function () {
                /// <summary>
                /// Whether time should be cleared in edited date/time
                /// </summary>
                /// <value type="Boolean" />
                return this._tagetControlID;
            },
            set_tagetControlID: function (value) {
                if (this._tagetControlID != value) {
                    this._tagetControlID = value;
                    this.raisePropertyChanged("_tagetControlID");
                }
            },
            get_clearTime: function () {
                /// <summary>
                /// Whether time should be cleared in edited date/time
                /// </summary>
                /// <value type="Boolean" />

                return this._clearTime;
            },
            set_clearTime: function (value) {
                if (this._clearTime != value) {
                    this._clearTime = value;
                    this.raisePropertyChanged("_clearTime");
                }
            },

            get_animated: function () {
                /// <summary>
                /// Whether changing modes is animated
                /// </summary>
                /// <value type="Boolean" />

                return this._animated;
            },
            set_animated: function (value) {
                if (this._animated != value) {
                    this._animated = value;
                    this.raisePropertyChanged("animated");
                }
            },

            get_enabled: function () {
                /// <value type="Boolean">
                /// Whether this behavior is available for the current element
                /// </value>

                return this._enabled;
            },
            set_enabled: function (value) {
                if (this._enabled != value) {
                    this._enabled = value;
                    this.raisePropertyChanged("enabled");
                }
            },
            get_readOnly: function () {
                return this._readOnly;
            },
            set_readOnly: function (value) {
                if (this._readOnly != value) {
                    this._readOnly = value;
                    this.raisePropertyChanged("readOnly");
                }
            },

            get_button: function () {
                /// <value type="Sys.UI.DomElement">
                /// The button to use to show the calendar (optional)
                /// </value>

                return this._button;
            },
            set_button: function (value) {
                if (this._button != value) {
                    if (this._button && this.get_isInitialized()) {
                        $common.removeHandlers(this._button, this._button$delegates);
                    }
                    this._button = value;
                    if (this._button && this.get_isInitialized()) {
                        $addHandlers(this._button, this._button$delegates);
                    }
                    this.raisePropertyChanged("button");
                }
            },
            get_textboxID: function () {
                return this._textboxID;
            },
            set_textboxID: function (value) {
                this._textboxID = value;
            },
            get_popupPosition: function () {
                /// <value type="Sys.Extended.UI.CalendarPosition">
                /// Where the popup should be positioned relative to the target control.
                /// Can be BottomLeft (Default), BottomRight, TopLeft, TopRight.
                /// </value>

                return this._popupPosition;
            },
            set_popupPosition: function (value) {
                if (this._popupPosition != value) {
                    this._popupPosition = value;
                    this.raisePropertyChanged('popupPosition');
                }
            },

            get_format: function () {
                /// <value type="String">
                /// The format to use for the date value
                /// </value>

                return this._format;
            },
            set_format: function (value) {
                if (this._format != value) {
                    this._format = value;
                    this.raisePropertyChanged("format");
                }
            },

            get_todaysDateFormat: function () {
                /// <value type="String">
                /// The format to use for the todays date
                /// </value>

                return this._todaysDateFormat;
            },
            set_todaysDateFormat: function (value) {
                if (this._todaysDateFormat != value) {
                    this._todaysDateFormat = value;
                    this.raisePropertyChanged("todaysDateFormat");
                }
            },

            get_daysModeTitleFormat: function () {
                /// <value type="String">
                /// The format to use for the title when in days mode
                /// </value>

                return this._daysModeTitleFormat;
            },
            set_daysModeTitleFormat: function (value) {
                if (this._daysModeTitleFormat != value) {
                    this._daysModeTitleFormat = value;
                    this.raisePropertyChanged("daysModeTitleFormat");
                }
            },

            get_selectedDate: function () {
                /// <value type="Date">
                /// The date value represented by the text box
                /// </value>

                if (this._selectedDate == null) {
                    var value = this._textBox.value;
                    if (value) {
                        value = this._parseTextValue(value);
                        if (value) {
                            this._selectedDate = value.getDateOnly();
                        }
                    }
                }
                return this._selectedDate;
            },
            set_selectedDate: function (value) {
                if (value && (String.isInstanceOfType(value)) && (value.length != 0)) {
                    value = new Date(value);
                }

                //                if (value) {
                //                    value =value,'yyyy-mm-dd'; 
                //                }

                if (this._selectedDate != value) {
                    this._selectedDate = value;
                    this._selectedDateChanging = true;
                    var text = "";
                    if (value) {
                        text = value.localeFormat(this._format);

                        if (!this._clearTime) {
                            var tbvalue = this._textBox.value;
                            if (tbvalue) {
                                tbvalue = this._parseTextValue(tbvalue);
                            }
                            if (tbvalue) {
                                if (value != tbvalue.getDate()) {
                                    text = value.add(tbvalue.getTimeOfDay()).localeFormat(this._format);
                                }
                            }
                        }
                    }
                    if (text != this._textBox.value) {
                        this._textBox.value = text;
                        this._clientStateField.value = text;
                        this._fireChanged();
                    }
                    this._selectedDateChanging = false;
                    this.invalidate();
                    this.raisePropertyChanged("selectedDate");
                }
            },

            get_defaultView: function () {
                /// <value type="Sys.Extended.UI.CalendarDefaultView">
                /// The default view of the calendar when it first pops up.
                /// </value>

                return this._defaultView;
            },
            set_defaultView: function (value) {
                if (this._defaultView != value) {
                    this._defaultView = value;
                    this.raisePropertyChanged("defaultView");
                }
            },

            get_visibleDate: function () {
                /// <summary>
                /// The date currently visible in the calendar
                /// </summary>
                /// <value type="Date" />

                return this._visibleDate;
            },
            set_visibleDate: function (value) {
                if (value) value = value.getDateOnly();
                if (this._visibleDate != value) {
                    this._switchMonth(value, !this._isOpen);
                    this.raisePropertyChanged("visibleDate");
                }
            },

            get_isOpen: function () {
                /// <value type="Boolean">
                /// Whether the calendar is open
                /// </value>
                return this._isOpen;
            },

            get_todaysDate: function () {
                /// <value type="Date">
                /// The date to use for "Today"
                /// </value>
                if (this._todaysDate != null) {
                    return this._todaysDate;
                }
                return new Date(); //.getDateOnly();
            },
            set_todaysDate: function (value) {
                if (value) value = value.getDateOnly();
                if (this._todaysDate != value) {
                    this._todaysDate = value;
                    this.invalidate();
                    this.raisePropertyChanged("todaysDate");
                }
            },

            get_firstDayOfWeek: function () {
                /// <value type="Sys.Extended.UI.FirstDayOfWeek">
                /// The day of the week to appear as the first day in the calendar
                /// </value>

                return this._firstDayOfWeek;
            },
            set_firstDayOfWeek: function (value) {
                if (this._firstDayOfWeek != value) {
                    this._firstDayOfWeek = value;
                    this.invalidate();
                    this.raisePropertyChanged("firstDayOfWeek");
                }
            },

            get_cssClass: function () {
                /// <value type="String">
                /// The CSS class selector to use to change the calendar's appearance
                /// </value>

                return this._cssClass;
            },
            set_cssClass: function (value) {
                if (this._cssClass != value) {
                    if (this._cssClass && this.get_isInitialized()) {
                        Sys.UI.DomElement.removeCssClass(this._container, this._cssClass);
                    }
                    this._cssClass = value;
                    if (this._cssClass && this.get_isInitialized()) {
                        Sys.UI.DomElement.addCssClass(this._container, this._cssClass);
                    }
                    this.raisePropertyChanged("cssClass");
                }
            },

            get_todayButton: function () {
                /// <value type="Sys.UI.DomElement">
                /// The button used to select todays date
                /// </value>

                return this._today;
            },

            get_dayCell: function (row, col) {
                /// <value type="Sys.UI.DomElement">
                /// Gets the day cell at the specified row or column
                /// </value>
                if (this._daysBody) {
                    return this._daysBody.rows[row].cells[col].firstChild;
                }
                return null;
            },

            add_showing: function (handler) {
                /// <summary>
                /// Adds an event handler for the <code>showiwng</code> event.
                /// </summary>
                /// <param name="handler" type="Function">
                /// The handler to add to the event.
                /// </param>
                /// <returns />

                this.get_events().addHandler("showing", handler);
            },
            remove_showing: function (handler) {
                /// <summary>
                /// Removes an event handler for the <code>showing</code> event.
                /// </summary>
                /// <param name="handler" type="Function">
                /// The handler to remove from the event.
                /// </param>
                /// <returns />

                this.get_events().removeHandler("showing", handler);
            },
            raiseShowing: function (eventArgs) {
                /// <summary>
                /// Raise the showing event
                /// </summary>
                /// <param name="eventArgs" type="Sys.CancelEventArgs" mayBeNull="false">
                /// Event arguments for the showing event
                /// </param>
                /// <returns />

                var handler = this.get_events().getHandler('showing');
                if (handler) {
                    handler(this, eventArgs);
                }
            },

            add_shown: function (handler) {
                /// <summary>
                /// Adds an event handler for the <code>shown</code> event.
                /// </summary>
                /// <param name="handler" type="Function">
                /// The handler to add to the event.
                /// </param>
                /// <returns />

                this.get_events().addHandler("shown", handler);
            },
            remove_shown: function (handler) {
                /// <summary>
                /// Removes an event handler for the <code>shown</code> event.
                /// </summary>
                /// <param name="handler" type="Function">
                /// The handler to remove from the event.
                /// </param>
                /// <returns />

                this.get_events().removeHandler("shown", handler);
            },
            raiseShown: function () {
                /// <summary>
                /// Raise the <code>shown</code> event
                /// </summary>
                /// <returns />

                var handlers = this.get_events().getHandler("shown");
                if (handlers) {
                    handlers(this, Sys.EventArgs.Empty);
                }
            },

            add_hiding: function (handler) {
                /// <summary>
                /// Adds an event handler for the <code>hiding</code> event.
                /// </summary>
                /// <param name="handler" type="Function">
                /// The handler to add to the event.
                /// </param>
                /// <returns />

                this.get_events().addHandler("hiding", handler);
            },
            remove_hiding: function (handler) {
                /// <summary>
                /// Removes an event handler for the <code>hiding</code> event.
                /// </summary>
                /// <param name="handler" type="Function">
                /// The handler to remove from the event.
                /// </param>
                /// <returns />

                this.get_events().removeHandler("hiding", handler);
            },
            raiseHiding: function (eventArgs) {
                /// <summary>
                /// Raise the hiding event
                /// </summary>
                /// <param name="eventArgs" type="Sys.CancelEventArgs" mayBeNull="false">
                /// Event arguments for the hiding event
                /// </param>
                /// <returns />

                var handler = this.get_events().getHandler('hiding');
                if (handler) {
                    handler(this, eventArgs);
                }
            },

            add_hidden: function (handler) {
                /// <summary>
                /// Adds an event handler for the <code>hidden</code> event.
                /// </summary>
                /// <param name="handler" type="Function">
                /// The handler to add to the event.
                /// </param>
                /// <returns />

                this.get_events().addHandler("hidden", handler);
            },
            remove_hidden: function (handler) {
                /// <summary>
                /// Removes an event handler for the <code>hidden</code> event.
                /// </summary>
                /// <param name="handler" type="Function">
                /// The handler to remove from the event.
                /// </param>
                /// <returns />

                this.get_events().removeHandler("hidden", handler);
            },
            raiseHidden: function () {
                /// <summary>
                /// Raise the <code>hidden</code> event
                /// </summary>
                /// <returns />

                var handlers = this.get_events().getHandler("hidden");
                if (handlers) {
                    handlers(this, Sys.EventArgs.Empty);
                }
            },

            add_dateSelectionChanged: function (handler) {
                /// <summary>
                /// Adds an event handler for the <code>dateSelectionChanged</code> event.
                /// </summary>
                /// <param name="handler" type="Function">
                /// The handler to add to the event.
                /// </param>
                /// <returns />

                this.get_events().addHandler("dateSelectionChanged", handler);
            },
            remove_dateSelectionChanged: function (handler) {
                /// <summary>
                /// Removes an event handler for the <code>dateSelectionChanged</code> event.
                /// </summary>
                /// <param name="handler" type="Function">
                /// The handler to remove from the event.
                /// </param>
                /// <returns />

                this.get_events().removeHandler("dateSelectionChanged", handler);
            },
            raiseDateSelectionChanged: function () {
                /// <summary>
                /// Raise the <code>dateSelectionChanged</code> event
                /// </summary>
                /// <returns />

                var handlers = this.get_events().getHandler("dateSelectionChanged");
                if (handlers) {
                    handlers(this, Sys.EventArgs.Empty);
                }
            },

            //    initialize: function() {
            //        /// <summary>
            //        /// Initializes the components and parameters for this behavior
            //        /// </summary>

            //        Sys.Extended.UI.CalendarBehavior.callBaseMethod(this, "initialize");

            //        var elt = this.get_element();
            //        $addHandlers(elt, this._element$delegates);

            //        if (this._button) {
            //            $addHandlers(this._button, this._button$delegates);
            //        }

            //        this._modeChangeMoveTopOrLeftAnimation = new Sys.Extended.UI.Animation.LengthAnimation(null, null, null, "style", null, 0, 0, "px");
            //        this._modeChangeMoveBottomOrRightAnimation = new Sys.Extended.UI.Animation.LengthAnimation(null, null, null, "style", null, 0, 0, "px");
            //        this._modeChangeAnimation = new Sys.Extended.UI.Animation.ParallelAnimation(null, .25, null, [this._modeChangeMoveTopOrLeftAnimation, this._modeChangeMoveBottomOrRightAnimation]);

            //        var value = this.get_selectedDate();
            //        if (value) {
            //            this.set_selectedDate(value);
            //        }
            //    },
            get_DateFormat: function () {
                return this._DateFormat;
            },
            set_DateFormat: function (value) {
                this._DateFormat = value;
            },
            get_ShowCelenderICO: function () {
                return this._ShowCelenderICO;
            },
            set_ShowCelenderICO: function (value) {
                this._ShowCelenderICO = value;
            },
            get_CallbackID: function () {
                return this._CallbackID;
            },
            set_CallbackID: function (value) {
                this._CallbackID = value;
            },

            get_My97DatePickerHtm: function () {
                return this._My97DatePickerHtm;
            },
            set_My97DatePickerHtm: function (value) {
                this._My97DatePickerHtm = value;
            },
            saveClientState: function () {
                var date = this.textBox.value.trim();
                return Sys.Serialization.JavaScriptSerializer.serialize(date);
            },
            loadClientState: function () {
                if (this._clientStateField.value == '' || this._clientStateField.value == 'undefined') {
                    return;
                }
                this._clientState = Sys.Serialization.JavaScriptSerializer.deserialize(this._clientStateField.value);
            },
            get_clientStateField: function () {
                return this._clientStateField;
            },
            set_clientStateField: function (value) {
                if (this._clientStateField != value) {
                    this._clientStateField = value;
                    this.raisePropertyChanged('clientStateField');
                }
            }
            //属性  ----- 结束
        }
        // Optional descriptor for JSON serialization.
        //        $DatePicker.descriptor = {
        //            properties: [{ name: 'DateFormat', type: String },
        //             { name: 'CallbackID', type: String },
        //             { name: 'ShowCelenderICO', type: Boolean },
        //             { name: 'cssClass', type: String },
        //             { name: 'format', type: String },
        //             { name: 'todaysDateFormat', type: String },
        //             { name: 'daysModeTitleFormat', type: String },
        //             { name: 'clearTime', type: Boolean },
        //             { name: 'enabled', type: Boolean },
        //             { name: 'animated', type: Boolean },
        //             { name: 'firstDayOfWeek', type: String },
        //             { name: 'button', type: String },
        //             { name: 'popupPosition', type: Boolean },
        //             { name: 'selectedDate', type: Date },
        //             { name: 'defaultView', type: String },
        //             { name: 'showing', type: String },
        //             { name: 'shown', type: String },
        //             { name: 'hiding', type: String },
        //             { name: 'hidden', type: String },
        //             { name: 'dateSelectionChanged', type: Boolean}]
        //        }

        // Register the class as a type that inherits from Sys.UI.Control.
        $DatePicker.registerClass('Kevin.Controls.DatePicker', Sys.UI.Control);

        Kevin.Controls.CalendarPosition = function () {
            throw Error.invalidOperation();
        }
        Kevin.Controls.CalendarPosition.prototype = {
            BottomLeft: 0,
            BottomRight: 1,
            TopLeft: 2,
            TopRight: 3,
            Right: 4,
            Left: 5
        }

        Kevin.Controls.CalendarPosition.registerEnum("Kevin.Controls.CalendarPosition", false)
        Kevin.Controls.CalendarDefaultView = function () {
            throw Error.invalidOperation();
        }
        Kevin.Controls.CalendarDefaultView.prototype = {
            Days: 0,
            Months: 1,
            Years: 2
        }
        Kevin.Controls.CalendarDefaultView.registerEnum('Kevin.Controls.CalendarDefaultView');

        //
        Kevin.Controls.FirstDayOfWeek = function () {
            throw Error.invalidOperation();
        }
        Kevin.Controls.FirstDayOfWeek.prototype = {
            Sunday: 0,
            Monday: 1,
            Tuesday: 2,
            Wednesday: 3,
            Thursday: 4,
            Friday: 5,
            Saturday: 6,
            Default: 7
        }
        Kevin.Controls.FirstDayOfWeek.registerEnum("Kevin.Controls.FirstDayOfWeek", false)

        Kevin.Controls.DateFormat = function () {
            throw Error.invalidOperation();
        }
        Kevin.Controls.DateFormat.prototype = {
            Date: 0,
            DateTime: 1
        }
        Kevin.Controls.DateFormat.registerEnum('Kevin.Controls.DateFormat');
    } //execute
    if (window.Sys && Sys.loader) {
        Sys.loader.registerScript(ScriptName, ["DatePicker"], null, execute);
    }
    else {
        execute();
    }
})();
//if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();